<template>
  <div class="container" :style="'height: ' + docheight + 'px'">
    <leftcont></leftcont>
    <div class="righCont">
      <topcont></topcont>
      <div class="content">
        <div class="payTable">
          <div class="trendTop">技师列表({{ total }})</div>
          <div class="tableCont">
            <div class="tableSerchCont">
              <div class="serchItem">
                <el-input
                  v-model="serchVal"
                  placeholder="请输入技师昵称"
                ></el-input>
              </div>
              <div class="headBtn">
                <btn value="搜索" @click="serchFn"></btn>
              </div>
              <div class="headBtn">
                <btn value="新增" @click="addFn"></btn>
              </div>
            </div>
            <el-table :data="tableData" style="width: 100%">
              <el-table-column
                prop="technician_name"
                show-overflow-tooltip
                label="技师姓名"
              >
              </el-table-column>
              <el-table-column prop="technician_head_img" label="技师头像">
                <template slot-scope="scope">
                  <img
                    style="height: 40px;"
                    :src="scope.row.technician_head_img + ossSrc"
                  />
                </template>
              </el-table-column>
              <el-table-column v-if="false" prop="earnest_money" label="保证金">
              </el-table-column>

              <el-table-column prop="technician_performance" label="总业绩">
              </el-table-column>
              <el-table-column prop="technician_order" label="订单总数">
              </el-table-column>
              <el-table-column prop="qx_cs" label="取消订单"> </el-table-column>
              <el-table-column prop="technician_score" label="评分">
              </el-table-column>
              <el-table-column prop="technician_status" label="服务状态">
                <template slot-scope="scope">
                  <div class="ctrolBtn">
                    <div class="greenBtn" v-if="scope.row.service_status == 1">
                      可服务
                    </div>
                    <div class="greenBtn" v-if="scope.row.service_status == 2">
                      服务中
                    </div>
                    <div class="redBtn" v-if="scope.row.service_status == 3">
                      休息中
                    </div>
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="technician_status" label="状态">
                <template slot-scope="scope">
                  <div class="ctrolBtn">
                    <div
                      class="greenBtn"
                      v-if="scope.row.technician_status == 1"
                    >
                      正常
                    </div>
                    <div class="redBtn" v-if="scope.row.technician_status == 2">
                      禁用
                    </div>
                  </div>
                </template>
              </el-table-column>
              <el-table-column width="200" label="操作">
                <template slot-scope="scope">
                  <div class="ctrolBtn">
                    <div class="text_btn redBtn" @click="delFn(scope.row)">
                      删除
                    </div>
                    <div class="text_btn redBtn" @click="showMaskFn(scope.row)">
                      扣费
                    </div>
                    <div class="text_btn blueBtn" @click="editFn(scope.row)">
                      编辑
                    </div>
                    <div class="text_btn greenBtn" @click="detailFn(scope.row)">
                      详情
                    </div>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <div class="pageCont">
              <el-pagination
                background
                layout="prev, pager, next"
                :page-size="per_page"
                :current-page="page"
                @current-change="pageFn"
                :total="total"
              >
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog title="提示" :visible.sync="showKfMask" width="30%">
      <el-form ref="form" :model="kfInfo" label-width="80px">
        <el-form-item label="扣费金额">
          <el-input v-model="kfInfo.money"></el-input>
        </el-form-item>
        <el-form-item label="扣费说明">
          <el-input v-model="kfInfo.remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showKfMask = false">取 消</el-button>
        <el-button type="primary" @click="downFn(maskItem)">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import leftcont from "@/components/leftCont.vue";
import topcont from "@/components/topCont.vue";
import btn from "@/components/public/btn.vue";
import { Technician, delTech, chargingMoney } from "@/http/api";

export default {
  components: { leftcont, topcont, btn },
  data() {
    return {
      serchVal: "",

      tableData: [],
      page: 1,
      per_page: 5,
      total: 0,
      showKfMask: false,
      maskItem: {},
      kfInfo: {
        money: "",
        remark: ""
      }
    };
  },
  props: {},
  methods: {
    addFn() {
      this.$router.push({ path: "/techAdd" });
    },
    detailFn(item) {
      this.$router.push({
        path: "/techDetail",
        query: { id: item.technician_id }
      });
    },
    editFn(item) {
      this.$router.push({
        path: "/techEdit",
        query: { id: item.technician_id }
      });
    },
    showMaskFn(item) {
      this.maskItem = item;
      this.showKfMask = true;
    },
    downFn(item) {
      let data = {
        technician_id: item.technician_id,
        remark: this.kfInfo.remark,
        money: this.kfInfo.money
      };
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(255, 255, 255, 0.7)"
      });
      chargingMoney(data)
        .then(res => {
          if (res.data.code == 1) {
            this.$message({
              message: "扣费成功",
              type: "success"
            });
            this.showKfMask = false;
            this.getdata();
          } else {
            this.$message(res.data.msg);
          }
          loading.close();
        })
        .catch(err => {
          loading.close();
          this.$message("服务器请求超时");
        });
    },
    delFn(item) {
      this.$confirm("确定删除该技师吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let data = {
          technician_id: item.technician_id
        };
        const loading = this.$loading({
          lock: true,
          text: "Loading",
          spinner: "el-icon-loading",
          background: "rgba(255, 255, 255, 0.7)"
        });
        delTech(data)
          .then(res => {
            if (res.data.code == 1) {
              this.$message({
                type: "success",
                message: res.data.msg
              });
              this.getdata();
            } else {
              this.$message(res.data.msg);
            }
            loading.close();
          })
          .catch(err => {
            loading.close();
            this.$message("服务器请求超时");
          });
      });
    },
    pageFn(index) {
      this.page = index;
      this.getdata();
    },
    serchFn() {
      this.page = 1;
      this.total = 0;
      this.getdata();
    },
    getdata() {
      var data = {
        technician_name: this.serchVal,
        page: this.page,
        per_page: this.per_page
      };
      Technician(data)
        .then(res => {
          if (res.data.code == 1) {
            this.tableData = res.data.data.data; //把最新的数组赋值给tableData
            this.total = res.data.data.total;
          } else {
            this.$message(res.data.msg);
          }
        })
        .catch(err => {
          this.$message("服务器请求超时");
        });
    }
  },
  mounted() {},
  created() {
    this.getdata();
  }
};
</script>

<style scoped lang="less">
.container {
  width: 100%;
  display: flex;
  overflow: hidden;
  .righCont {
    display: flex;
    flex-direction: column;
    flex: 1;
    margin-left: 15px;
    height: 100%;
    width: 10px;
    background-color: #f4f8ff;
    .content {
      padding: 20px;
      box-sizing: border-box;
      width: 100%;
      flex: 1;
      overflow: auto;
      .payTable {
        margin-top: 20px;
        width: 100%;
        background-color: #fff;
        padding: 15px;
        box-sizing: border-box;
        .trendTop {
          font-weight: bold;
          font-size: 16px;
          cursor: pointer;
        }
        .tableCont {
          width: 100%;
          margin-top: 15px;
          .redBtn {
            color: #f56c6c;
          }
          .blueBtn {
            color: #96a1fe;
          }
          .greenBtn {
            color: #85ce61;
          }
          .blackBtn {
            color: #666;
          }
          .tableSerchCont {
            width: 100%;
            display: flex;
            justify-content: flex-end;
            margin-bottom: 10px;
            .serchItem {
              width: 150px;
              margin-left: 10px;
            }
            .headBtn {
              margin-left: 10px;
            }
          }
          .ctrolBtn {
            display: flex;
            .text_btn {
              margin: 0 5px;
              cursor: pointer;
              font-size: 14px;
            }
          }
          .pageCont {
            padding: 30px 0;
            display: flex;
            justify-content: center;
          }
        }
      }
    }
  }
}
</style>
